<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/7/18
 * Time: 17:36
 */

namespace app\admin\controller\shop;


use think\Controller;
use think\Db;

class Banner extends Controller
{
    public function page(){
        $item=Db::name("ewei_shop_banner")
            ->where("iswxapp","=",0)
            ->where("uniacid","=",1)
            ->order("displayorder","desc")
            ->paginate(10);
        $page=$item->render();
        $this->assign("page",$page);
        $this->assign("item",$item);
        return $this->fetch("index");
    }

    public function edit(){
        $model=new \app\admin\model\Adv();
        if($this->request->isPost()){
            $data=$this->request->param();
            $id=$this->request->has("id");
            if($id){//更新
                $model->name("ewei_shop_banner")->insert($data,true);
            }else{//插入
                $model->name("ewei_shop_banner")->insert($data);
            }
            $this->redirect("page");
        }else{
            if($this->request->has("id")){
                $id=$this->request->param("id");
                $item=$model->name("ewei_shop_banner")
                    ->where("iswxapp","=",0)
                    ->where("uniacid","=",1)
                    ->where("id",$id)
                    ->find();
                $this->assign("item",$item);
            }else{

            }
            $this->assign("title","添加幻灯片");
            return $this->fetch();
        }

    }

    public function delete(){
        $model=new \app\admin\model\Adv();
        $id=$this->request->param('id');
        $res=$model->name("ewei_shop_banner")->insert([
            "id"            =>$id,
            "iswxapp"       =>1
        ],true);
        if($res){
            $this->success("删除成功");
        }else{
            $this->error("删除失败");
        }
    }

    public function add(){
        return  $this->fetch();
    }

    public function search(){
        $model=new \app\admin\model\Adv();
        $post=$this->request->param();
        $content=$post['content'];
        $enabled=$post['enabled'];
        $item=$model->name("ewei_shop_banner")
            ->where([
                "iswxapp"       =>0,
                "uniacid"       =>1
            ])->order("displayorder","desc")
            ->whereLike( "bannername",'%'.$content.'%',"AND")
            ->paginate(10);
        $page=$item->render();
        $this->assign("page",$page);
        $this->assign("item",$item);
        return $this->fetch("index");

    }

}